﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Medical.Entity;
using Medical.Business;
using System.Data;

/// <summary>
/// 答疑列表页面
/// </summary>
public partial class FaqList : WebPage
{
    /// <summary>
    /// 文章类型
    /// </summary>
    protected ArticelTypeEnum eType;

    protected int nSortID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        InitConfig();
        if (!Page.IsPostBack)
        {
            InitList();
        }
    }

    /// <summary>
    /// 数据初始化
    /// </summary>
    protected void InitConfig()
    {
        if (RouteData.Values["urlname"] != null)
        {
            string strUrlName = RouteData.Values["urlname"].ToString();
            BisSortInfo bisSortInfo = new BisSortInfo();
            DataTable dtSort = bisSortInfo.GetSortInfo(strUrlName);
            ltlPageUrl.Text = "<a href=\"/faq/\" target=\"_blank\" title=\"有问必答\">有问必答</a> &gt; ";
            if (dtSort != null && dtSort.Rows.Count > 0)
            {
                nSortID = Convert.ToInt32(dtSort.Rows[0]["ID"]);
                eType = (ArticelTypeEnum)Convert.ToInt32(dtSort.Rows[0]["Type"]);
                if (dtSort.Rows[0]["PID"].ToString() != string.Empty)
                {
                    faqsortlist.Visible = false;
                    ltlPageUrl.Text += "<a href=\"/faq/" + dtSort.Rows[0]["PPageUrlName"].ToString() + "/\" title=\"" + dtSort.Rows[0]["PName"].ToString() + "\" target=\"_blank\">" + Server.HtmlEncode(dtSort.Rows[0]["PName"].ToString()) + "</a> &gt; ";
                }
                else
                {
                    DataTable dtSubSort = bisSortInfo.GetSortList(nSortID, eType);
                    ltlSortName.Text = Server.HtmlEncode(dtSort.Rows[0]["Name"].ToString());
                    rptSort.DataSource = dtSubSort;
                    rptSort.DataBind();
                    faqsortlist.Visible = true;
                }
                ltlPageUrl.Text += Server.HtmlEncode(dtSort.Rows[0]["Name"].ToString());

                string strPageTitle = string.IsNullOrEmpty(dtSort.Rows[0]["PageTitle"].ToString()) ? (dtSort.Rows[0]["Name"].ToString() + "_" + strWebTitle) : dtSort.Rows[0]["PageTitle"].ToString();
                SetPageInfo(strPageTitle, dtSort.Rows[0]["PageKeywords"].ToString(), dtSort.Rows[0]["PageDescription"].ToString());
            }
            else
            {
                Response.Redirect("/404.html");
            }
        }
        else
        {
            Response.Redirect("/404.html");
        }
    }

    /// <summary>
    /// 获取列表
    /// </summary>
    protected void InitList()
    {
        int nRecordCount = 0;
        int nPageCount = 0;
        DataTable dtFaq = new BisFeedBack().GetFeedBackList(nSortID,0,true, string.Empty, 0,string.Empty,string.Empty, anpPage.CurrentPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        anpPage.RecordCount = nRecordCount;
        if (nRecordCount == 0)
            noData.Visible =true;
        else
            noData.Visible = false;
        rptFaq.DataSource = dtFaq;
        rptFaq.DataBind();
        dtFaq.Dispose();

        DataTable dtFaq1 = new BisFeedBack().GetTopList(15, 0);
        rptFaq1.DataSource = dtFaq1;
        rptFaq1.DataBind();
        dtFaq1.Dispose();
    }

    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="src"></param>
    /// <param name="e"></param>
    protected void anpPage_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        anpPage.CurrentPageIndex = e.NewPageIndex;
        InitList();
    }

   
}